<?php
if(!defined('IN_IBEIKE')){
	exit('Access Denied');
}
$jsonout=array();
if($_GET['action']=='login'){
	//登录
	loaducenter();
	$username=!empty($_GET['username'])?$_GET['username']:'';
	$pw=!empty($_GET['password'])?$_GET['password']:'';
	list($uid)=uc_user_login($username,$pw);
	if($uid){
		$user=C::t('user_user')->fetch_by_username($username);
		dsetcookie('auth', authcode("{$user['password']}\t{$user['uid']}", 'ENCODE'), 86400 * 30, 1, true);
		$jsonout['status']='成功';
		$jsonout['refer']=$_GET['refer'];
	}else{
		switch($uid){
			case -1:$jsonout['status']='用户不存在';break;
			case -2:$jsonout['status']='密码错误';break;
			default:$jsonout['status']='未定义的返回';
		}
	}
}elseif($_GET['action']=='logout'){
	if($_G['uid']){
		$_G['cookie']['saltkey'] = random(8);
		dsetcookie('saltkey', $_G['cookie']['saltkey'], 86400 * 30, 1, 1);
		$jesonout['status']='logouttrue';
		header('Location:index.php');
	}else{
		$jsonout['status']='logoutfalse';
	}
}elseif($_GET['action']=='modifyuser'){
	//TODO:修改核心信息
}elseif($_GET['action']=='modifybasicinfo'){
	$data=array();//将修改 的信息写入这个数组,键为字段,值为修改内容
	$tid=$_G['uid'];//用户id
	C::t('user_user')->update_by_uid($tid,$data);
	//TODO:修改基本信息
}elseif($_GET['action']=='modifycredit'){
	$data=array();
	C::t('user_credit')->update_intfield_chage_by_uid($tid,$data,$order);
	//这里的积分修改要根据主键来修改,修改的字段和数量按字段=>修改量放在$data数组中,$order为1增加0减
	//TODO:修改积分
}elseif($_GET['action']=='checkin'){
	//签到
	$data=array();
	$data['uid']=$_G['uid'];
	$data['checktime']=time();
	$res=C::t('user_check')->insert($data);
	if($res){
		$ret=array();
		$ret['status']=1;
		$ret['cid']=$res;
		C::t('user_user')->update_checkcount_by_uid($_G['uid']);
	}else{
		$ret['status']=-1;
	}
	echo json_encode($ret);
	exit();
}elseif($_GET['action']=='changelocation'){
	//TODO:修改位置
}
//输出控制部分

if($returntype=='html'){
	//TODO:输出界面
}else if($returntype=='xml'){
	//TODO:输出xml
}else{
	echo json_encode($jsonout);
}
exit();